<?php

if (!defined('MEDIAWIKI'))
    die;

/**
 * 
 */
class SpecialProfil extends SpecialPage {

    function __construct() {
        parent::__construct('SpecialProfil');
    }

    function execute($test) {
        $request = $this->getRequest();
        $action = $request->getText('action');
         $user_name=$request->getText('user_name', $this->getUser());
        $mDb = wfGetDB(DB_SLAVE);

        $tables = array('user');

        $fields = array('user_id', 'user_name', 'user_real_name', 'user_email');

        $options = $join_conds = array();
        $conds = array("user_name='" . $user_name . "'");
        $fname = __METHOD__ . ' (SpecialProfil)';
        if ($action == 'edit' || $action != 'valider')
            $res = $mDb->select($tables, $fields, $conds);

        if ($action == "edit") {

            $tpl = new Profilcreate($this->getUser(), $res);
        } else {
            if ($action == "valider") {

                $values = array('user_name' => $request->getText('user_name', $this->getUser()),
                    'user_real_name' => $request->getText('user_real_name'),
                    'user_password' => $request->getText('pwd'),
                );
                $up = $mDb->update("user", $values, $conds);
                $res = $mDb->select($tables, $fields, $conds);
            }

            $tpl = new ProfilAffiche($this->getUser(), $res);
        }
        $out = $this->getOutput();
        $out->addTemplate($tpl);
    }

}
